<?php
JLoader::register("PCalendarModellistview", OC_App::getAppPath('calendar') . "/lib/listview.php");

OCP\JSON::callCheck();
if(!OC_User::isLoggedIn()) {
   echo '您需要先登录';
   exit;
}

$jobseekerid = JRequest::getInt('jobseekerid', 0);

$model = new PCalendarModellistview();

$interviewlist = $model->getUserInterviewList($jobseekerid);
$round = 0;
$objectid = 0;
$interview_stat = PCalendarHelper::NEW_INTERVIEW;
if(!empty($interviewlist) && count($interviewlist)>=1){
   $round = $interviewlist[0]['round'];
   $objectid = $interviewlist[0]['parent'];
   $result = $interviewlist[0]['result'];
   $offer_objectid = $interviewlist[0]['last_offer_objectid'];
   $entry_stat = $interviewlist[0]['entry_stat'];
   $last_offer_objectid = $interviewlist[0]['last_offer_objectid'];
   $last_interview_objectid = $interviewlist[0]['last_interview_objectid'];

   $now = PFactory::getDate();
   $startdate = PFactory::getDate($interviewlist[0]['startdate']);
   $enddate =PFactory::getDate($interviewlist[0]['enddate']);
   //已进入入职流程
   if(!empty($entry_stat)){
      $interview_stat = PCalendarHelper::ENTRY_INTERVIEW;
   //已发送offer
   }else if(!empty($offer_objectid)){
      if($last_offer_objectid > $last_interview_objectid) {
         $interview_stat = PCalendarHelper::OFFER_INTERVIEW;
      } elseif ($last_interview_objectid > $last_offer_objectid) {
         $interview_stat = PCalendarHelper::UPDATE_INTERVIEW;
      }
   //面试取消
   }else if($result == PCalendarHelper::INTERVIEW_RESULT_CANCEL){
      $interview_stat = PCalendarHelper::RESET_INTERVIEW;
   //$round存在:已安排面试
   }else if($round){
      $interview_stat = PCalendarHelper::UPDATE_INTERVIEW;
   //$round不存在或为零:未安排面试
   }else{
      $interview_stat = PCalendarHelper::NEW_INTERVIEW;
   }
}

jexit(jsonSuccess(array('round'=>$round,'objectid'=>$objectid,'interview_stat'=>$interview_stat), null, null, false));